package com.yfqy.app.enums;

import lombok.Getter;

@Getter
public enum OrderType {
    NORMAL((byte) 1, "普通订单"),
    FULL_DISCOUNT((byte) 2, "满减活动订单"),
    DISCOUNT((byte) 3, "折扣活动订单"),
    SPECIAL((byte) 4, "特价订单"),
    GROUP_BUY((byte) 5, "拼团订单");

    private final byte code;
    private final String desc;

    OrderType(byte code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // getters
    public static OrderType of(byte code) {
        // 根据code返回对应枚举
        for (OrderType value : values()) {
            if (code == value.code) {
                return value;
            }
        }
        return null;
    }

    public static Byte coverToPromotionType(byte code) {
        OrderType orderType = of(code);
        if (orderType == null) {
            return null;
        }
        return switch (orderType) {
            case SPECIAL -> PromotionType.Special.getType();
            case DISCOUNT -> PromotionType.Discount.getType();
            case FULL_DISCOUNT -> PromotionType.Full.getType();
            default -> null;
        };
    }
}
